package src;

import src.queue.ArrayQueue;
import src.queue.CircularQueue;
import src.queue.LinkedListQueue;
import src.stack.ArrayStack;
import src.stack.LinkedListStack;

/**
 * @author Dream
 */
public class Main {
    public static void main(String[] args) {
        //实现循环队列
        arrayStack();
        //用带尾指针的链表实现栈
        linkedListStack();
        //用数组实现队列
        arrayQueue();
        //用链表实现队列
        linkedListQueue();

        System.out.println("\n-------------------进阶部分------------------\n");


        //实现循环队列
        circularQueue();
    }

    /**
     * 循环队列
     */
    private static void circularQueue() {
        System.out.println("1.实现循环队列\n");
        CircularQueue<String> circularQueue = new CircularQueue<>(3);
        System.out.println("队列是否为空：" + circularQueue.isEmpty());
        for (int i = 0; i < 40; i += 10) {
            circularQueue.add(String.valueOf(i));
        }
        System.out.println("移除头部元素：" + circularQueue.remove());
        System.out.println("移除头部元素：" + circularQueue.remove());
        System.out.println("移除头部元素：" + circularQueue.remove());
        System.out.println("移除头部元素：" + circularQueue.remove());
        circularQueue.add("10");
        System.out.println("查看队列头部元素：" + circularQueue.peek());
    }

    /**
     * 用链表实现队列
     */
    private static void linkedListQueue() {
        System.out.println("\n4.用链表实现队列\n");
        LinkedListQueue<String> linkedListQueue = new LinkedListQueue<>();
        System.out.println("队列是否为空：" + linkedListQueue.isEmpty());
        for (int i = 0; i < 40; i += 10) {
            linkedListQueue.add(String.valueOf(i));
        }
        System.out.println("查看队列头部元素：" + linkedListQueue.peek());
        System.out.println("移除头部元素：" + linkedListQueue.remove());
        System.out.println("查看队列头部元素：" + linkedListQueue.peek());
        System.out.println("队列元素个数：" + linkedListQueue.size() + "个");
        System.out.println("队列是否为空：" + linkedListQueue.isEmpty());
    }

    /**
     * 用数组实现队列
     */
    private static void arrayQueue() {
        System.out.println("\n3.用数组实现队列\n");
        ArrayQueue<String> arrayQueue = new ArrayQueue<>(4);
        System.out.println("队列是否为空：" + arrayQueue.isEmpty());
        for (int i = 0; i < 40; i += 10) {
            arrayQueue.add(String.valueOf(i));
        }
        System.out.println("查看队列头部元素：" + arrayQueue.peek());
        System.out.println("移除头部元素：" + arrayQueue.remove());
        System.out.println("查看队列头部元素：" + arrayQueue.peek());
        System.out.println("队列元素个数：" + arrayQueue.size() + "个");
        System.out.println("队列是否为空：" + arrayQueue.isEmpty());
    }

    /**
     * 用带尾指针的链表实现栈
     */
    private static void linkedListStack() {
        System.out.println("\n2.用带尾指针的链表实现栈\n");
        LinkedListStack<String> linkedListPen = new LinkedListStack<>();
        System.out.println("栈是否为空：" + linkedListPen.isEmpty());
        for (int i = 0; i < 40; i += 10) {
            linkedListPen.push(String.valueOf(i));
        }
        linkedListPen.push(null);
        System.out.println("查看栈顶元素：" + linkedListPen.peek());
        System.out.println("出栈：" + linkedListPen.pop());
        System.out.println("查看栈顶元素：" + linkedListPen.peek());
        System.out.println("栈内元素个数：" + linkedListPen.size() + "个");
        System.out.println("栈是否为空：" + linkedListPen.isEmpty());
    }

    /**
     * 数组实现栈
     */
    private static void arrayStack() {
        System.out.println("1.用数组实现栈\n");
        ArrayStack<String> arrayPen = new ArrayStack(3);
        System.out.println("栈是否为空：" + arrayPen.isEmpty());
        arrayPen.push("10");
        arrayPen.push(null);
        arrayPen.push("30");
        arrayPen.push("40");
        System.out.println("查看栈顶元素：" + arrayPen.peek());
        System.out.println("出栈：" + arrayPen.pop());
        System.out.println("查看栈顶元素：" + arrayPen.peek());
        System.out.println("栈内元素个数：" + arrayPen.size() + "个");
        System.out.println("栈是否为空：" + arrayPen.isEmpty());
    }
}
